package com.yanqu.road.server.cmd.activity.operamask;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.OperaMaskProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.operamask.OperaMaskModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_OPERA_MASK_MOVE_BLOCK, desc = "")
public class OperaMaskMoveBlockCmd extends AbstractCommand {

    private int fromX;
    private int fromY;
    private int toX;
    private int toY;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OperaMaskProto.OperaMaskMoveBlockReqMsg reqMsg = OperaMaskProto.OperaMaskMoveBlockReqMsg.parseFrom(packet.getBytes());
        fromX = reqMsg.getFromX();
        fromY = reqMsg.getFromY();
        toX = reqMsg.getToX();
        toY = reqMsg.getToY();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(OperaMaskModule.class).moveBlock(fromX, fromY, toX, toY);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            OperaMaskProto.OperaMaskMoveBlockRespMsg.Builder builder = OperaMaskProto.OperaMaskMoveBlockRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_OPERA_MASK_MOVE_BLOCK, builder);
        }
    }
}
